package cc.rengu.igas.momp.core.service.trans;

import cc.rengu.igas.momp.common.constant.CommonConstant;
import cc.rengu.igas.momp.common.dao.MchntInfoMapper;
import cc.rengu.igas.momp.common.dao.StatisticsStatementInfoMapper;
import cc.rengu.igas.momp.common.dao.impl.MchntInfoMapperImpl;
import cc.rengu.igas.momp.common.dao.impl.StatisticsStatementInfoMapperImpl;
import cc.rengu.igas.momp.common.entity.StatisticsStatementQueryRespInfo;
import cc.rengu.igas.momp.common.entity.TBMchntBaseInfo;
import cc.rengu.igas.momp.common.entity.TMStat2CMchnt;
import cc.rengu.igas.momp.common.entity.TMStat2CMchntDay;
import cc.rengu.igas.momp.common.enums.McTypeEnum;
import cc.rengu.igas.momp.common.enums.RespCodeEnum;
import cc.rengu.igas.momp.facade.bean.MchntToClientMcStatInfoBean;
import cc.rengu.igas.momp.facade.bean.MchntToClientMcTxnStatInfoBean;
import cc.rengu.igas.momp.facade.request.QueryMchntToClientMcStatRequest;
import cc.rengu.igas.momp.facade.response.QueryMchntToClientMcStatResponse;
import cc.rengu.oltp.service.base.RadpService;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.enums.ChannelEnum;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.util.ConvertUtil;
import cc.rengu.oltp.utility.util.DateUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.base.StringUtil;
import com.alibaba.fastjson.JSON;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author : liujinan
 * @version 1.0.0
 * @date 2020/4/1
 * @Description: 商户对客类营销活动统计报表查询功能实现
 */
public class MchntToClientMcStatQueryService extends RadpService {
    //营销活动编号
    String mcNo;
    //营销活动类型
    String mcType;
    //营销活动表json字符串
    String initStatData;

    @Override
    protected int bizInit(String s) {
        return 0;
    }

    @Override
    protected int bizProcess(String s, int i) {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        try {
            QueryMchntToClientMcStatRequest queryMchntToClientMcStatRequest = new QueryMchntToClientMcStatRequest();
            ConvertUtil.convertOutput(queryMchntToClientMcStatRequest);

            QueryMchntToClientMcStatResponse queryMchntToClientMcStatResponse = new QueryMchntToClientMcStatResponse();
            queryMchntToClientMcStatResponse.setHeader(queryMchntToClientMcStatRequest.getHeader());
            BizResponse<QueryMchntToClientMcStatResponse> bizResponse = new BizResponse<>();
            bizResponse.setResult(queryMchntToClientMcStatResponse);

            // 服务调用
            BizResponse<QueryMchntToClientMcStatResponse> bizResponseNew = mchntToClientMcStatQuery(xmlTreeUtil, queryMchntToClientMcStatRequest, queryMchntToClientMcStatResponse);

            ConvertUtil.convertInput(bizResponseNew.getResult());

        } catch (BizException e) {
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, e.getCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, e.getMessage());
                xmlTreeUtil.setXmlTreeStringValue(CommonConstant.KEY_RESPDESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e1));
            }
        } catch (Exception e) {
            rglog.error(StringUtil.ExceptionToString(e));
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
                xmlTreeUtil.setXmlTreeStringValue(CommonConstant.KEY_RESPDESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e));
            }
        }

        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizTerminate(String s) {
        return 0;
    }


    private BizResponse<QueryMchntToClientMcStatResponse> mchntToClientMcStatQuery(XmlTreeUtil xmlTreeUtil, QueryMchntToClientMcStatRequest queryMchntToClientMcStatRequest, QueryMchntToClientMcStatResponse queryMchntToClientMcStatResponse) throws Exception {

        BizResponse<QueryMchntToClientMcStatResponse> bizResponse = new BizResponse<>();

        rglog.debug("TXN_NUM = {}", queryMchntToClientMcStatRequest.getHeader().getTxnNum());

        String queryClause = queryMchntToClientMcStatRequest.getHeader().getInstId() + queryMchntToClientMcStatRequest.getMcNo() + queryMchntToClientMcStatRequest.getMcName() +
                queryMchntToClientMcStatRequest.getMcType() + queryMchntToClientMcStatRequest.getMcStatus() + queryMchntToClientMcStatRequest.getMcOrgId();
        //获取商户信息
        TBMchntBaseInfo mchntBaseInfo = new TBMchntBaseInfo();
        mchntBaseInfo = getMchntBaseInfo(queryMchntToClientMcStatRequest);
        if (null != mchntBaseInfo) {
            //营销活动信息List
            List<StatisticsStatementQueryRespInfo> mcMoneyOffNOList = new ArrayList<>();
            List<StatisticsStatementQueryRespInfo> mcCouponNOList = new ArrayList<>();
            if (!StringUtil.isNullorEmpty(queryMchntToClientMcStatRequest.getMcNo())) {
                mcNo = queryMchntToClientMcStatRequest.getMcNo();
                mcType = mcNo.substring(2, 4);
                if (mcType.equals(McTypeEnum.COUPON_ALL.getMcTypeCode()) || mcType.equals(McTypeEnum.COUPON_FREE.getMcTypeCode())) {
                    //查询卡券类营销活动信息
                    getMcCouponListInfo(queryMchntToClientMcStatRequest, mcCouponNOList, mchntBaseInfo.getMchntArea());
                } else if (mcType.equals(McTypeEnum.REDUCTION_FIXED_AMOUNT.getMcTypeCode()) ||
                        mcType.equals(McTypeEnum.REDUCTION_RANDOM_AMOUNT.getMcTypeCode()) ||
                        mcType.equals(McTypeEnum.REDUCTION_FIXED_RATE.getMcTypeCode()) ||
                        mcType.equals(McTypeEnum.REDUCTION_RANDOM_RATE.getMcTypeCode())) {
                    //查询减免类营销活动信息
                    getMcMoneyOffListInfo(queryMchntToClientMcStatRequest, mcMoneyOffNOList, mchntBaseInfo.getMchntArea());
                }
            } else {
                //查询减免类营销活动信息
                getMcMoneyOffListInfo(queryMchntToClientMcStatRequest, mcMoneyOffNOList, mchntBaseInfo.getMchntArea());
                //查询卡券类营销活动信息
                getMcCouponListInfo(queryMchntToClientMcStatRequest, mcCouponNOList, mchntBaseInfo.getMchntArea());
            }
            if (mcCouponNOList.isEmpty() && mcMoneyOffNOList.isEmpty()) {
                rglog.error("根据查询条件<{}>查询到0条营销活动信息!", queryClause);
                queryMchntToClientMcStatResponse.setTotalPage(CommonConstant.ZERO_COMMON_CONSTANT);
                queryMchntToClientMcStatResponse.setTotalRows(CommonConstant.ZERO_COMMON_CONSTANT);
            } else {
                rglog.error("根据查询条件<{}>查询到0条营销活动信息!", queryClause);
                //减免类和卡券类营销活动信息汇总
                List<StatisticsStatementQueryRespInfo> mcInfoList = new ArrayList<>();
                //将减免类营销活动添加到mcNOList
                mcInfoList.addAll(mcMoneyOffNOList);
                //将卡券类营销活动添加到mcNOList
                mcInfoList.addAll(mcCouponNOList);

                List<MchntToClientMcStatInfoBean> MchntToClientMcStatInfoBeanListResult = new ArrayList<MchntToClientMcStatInfoBean>();

                //循环遍历上步查询到的营销活动
                for (StatisticsStatementQueryRespInfo statisticsStatementQueryRespInfo : mcInfoList) {
                    initStatData = statisticsStatementQueryRespInfo.getInitStatData();
                    //查询对客营销活动商户统计信息
                    List<TMStat2CMchnt> statToClientMchntMchntList = new ArrayList<>();
                    getAllStatToClientInfo(queryMchntToClientMcStatRequest, statisticsStatementQueryRespInfo.getMcNo(), statToClientMchntMchntList);
                    //如果对客营销活动商户统计表数据查询不为空
                    if (!statToClientMchntMchntList.isEmpty()) {
                        //将表数据转换为响应实体对象
                        List<MchntToClientMcStatInfoBean> MchntToClientMcStatInfoBeanList = statToClientMchntMchntList.stream().map(this::convertMchntToClientMcStatInfoBean).collect(Collectors.toList());

                        //循环遍历对客商户营销活动统计信息
                        for (MchntToClientMcStatInfoBean mchntToClientMcStatInfoBean : MchntToClientMcStatInfoBeanList) {
                            List<TMStat2CMchntDay> StatToClientMchntDayList = new ArrayList<>();
                            //查询对客营销活动商户单日统计信息
                            getAllStatToClientDayInfo(queryMchntToClientMcStatRequest, statisticsStatementQueryRespInfo.getMcNo(), StatToClientMchntDayList);
                            if (!StatToClientMchntDayList.isEmpty()) {
                                //将表数据转换为响应实体对象
                                List<MchntToClientMcTxnStatInfoBean> bankToClientMcTxnStatInfoList = StatToClientMchntDayList.stream().map(this::convertMchntToClientDayMcStatInfo).collect(Collectors.toList());
                                mchntToClientMcStatInfoBean.setTxnStatInfoList(bankToClientMcTxnStatInfoList);
                            } else {
                                continue;
                            }
                            MchntToClientMcStatInfoBeanListResult.add(mchntToClientMcStatInfoBean);
                        }
                    }
                }

                queryMchntToClientMcStatResponse.setTotalRows(String.valueOf(MchntToClientMcStatInfoBeanListResult.size()));
                if (queryMchntToClientMcStatRequest.getPageIndex().equals("-1") || queryMchntToClientMcStatRequest.getPageSize().equals("-1")) {
                    queryMchntToClientMcStatResponse.setTotalPage(CommonConstant.ONE_COMMON_CONSTANT);
                    queryMchntToClientMcStatResponse.setPageIndex(CommonConstant.ONE_COMMON_CONSTANT);
                    queryMchntToClientMcStatResponse.setPageSize(String.valueOf(MchntToClientMcStatInfoBeanListResult.size()));
                    //查询到的链表信息
                    queryMchntToClientMcStatResponse.setMcStatInfoList(MchntToClientMcStatInfoBeanListResult);
                } else {
                    if (0 == (MchntToClientMcStatInfoBeanListResult.size() % Integer.parseInt(queryMchntToClientMcStatRequest.getPageSize()))) {
                        queryMchntToClientMcStatResponse.setTotalPage(String.valueOf(MchntToClientMcStatInfoBeanListResult.size() / Math.abs(Integer.parseInt(queryMchntToClientMcStatRequest.getPageSize()))));
                    } else {
                        queryMchntToClientMcStatResponse.setTotalPage(String.valueOf(MchntToClientMcStatInfoBeanListResult.size() / Math.abs(Integer.parseInt(queryMchntToClientMcStatRequest.getPageSize())) + 1));
                    }

                    queryMchntToClientMcStatResponse.setPageIndex(queryMchntToClientMcStatRequest.getPageIndex());
                    queryMchntToClientMcStatResponse.setPageSize(queryMchntToClientMcStatRequest.getPageSize());
                    //按照分页返回查询到的数据
                    /* 分页查询 */
                    int fromIndex = Integer.parseInt(queryMchntToClientMcStatRequest.getPageIndex()) * Integer.parseInt(queryMchntToClientMcStatRequest.getPageSize());
                    int endIndex = fromIndex + Integer.parseInt(queryMchntToClientMcStatRequest.getPageSize());
                    if (fromIndex <= MchntToClientMcStatInfoBeanListResult.size()) {
                        List<MchntToClientMcStatInfoBean> subMcMoneyOffInfoList = MchntToClientMcStatInfoBeanListResult.subList(fromIndex, Math.min(endIndex, MchntToClientMcStatInfoBeanListResult.size()));
                        queryMchntToClientMcStatResponse.setMcStatInfoList(subMcMoneyOffInfoList);
                    }
                }
            }
        } else {
            //未查询到商户信息返回查询结果为0
            queryMchntToClientMcStatResponse.setTotalRows(CommonConstant.ZERO_COMMON_CONSTANT);
            queryMchntToClientMcStatResponse.setTotalPage(CommonConstant.ZERO_COMMON_CONSTANT);
        }

        bizResponse.setRspSysId(ChannelEnum.MOMP.getChannelType());
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        queryMchntToClientMcStatResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        queryMchntToClientMcStatResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        bizResponse.setResult(queryMchntToClientMcStatResponse);

        return bizResponse;
    }

    /**
     * @param queryMchntToClientMcStatRequest
     * @return void
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/4/2
     * @Description: 查询商户基本信息
     */
    private TBMchntBaseInfo getMchntBaseInfo(QueryMchntToClientMcStatRequest queryMchntToClientMcStatRequest) throws Exception {
        MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();
        return mchntInfoMapper.selectMompMchntBaseInfoByPrimaryKey(queryMchntToClientMcStatRequest.getHeader().getInstId(), queryMchntToClientMcStatRequest.getMchntNo());
    }

    /**
     * @param queryMchntToClientMcStatRequest
     * @param mcMoneyOffList
     * @return void
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/4/12
     * @Description: 查询减免类营销活动信息
     */
    private void getMcMoneyOffListInfo(QueryMchntToClientMcStatRequest queryMchntToClientMcStatRequest, List<StatisticsStatementQueryRespInfo> mcMoneyOffList, String mchntArea) {

        try {
            StatisticsStatementInfoMapper statisticsStatementInfoMapper = new StatisticsStatementInfoMapperImpl();
            List<StatisticsStatementQueryRespInfo> objectList = statisticsStatementInfoMapper.selectStatToClientMcMoneyOffListInfo(queryMchntToClientMcStatRequest.getHeader().getInstId(),
                    queryMchntToClientMcStatRequest.getMcNo(),
                    queryMchntToClientMcStatRequest.getMcName(),
                    queryMchntToClientMcStatRequest.getMcType(),
                    queryMchntToClientMcStatRequest.getMcStatus(),
                    queryMchntToClientMcStatRequest.getMchntNo(),
                    mchntArea);
            if (null != objectList) {
                mcMoneyOffList.addAll(objectList);
            }
        } catch (Exception e) {
            rglog.error("获取减免类营销活动列表信息失败!");
            throw new BizException(RespCodeEnum.GET_MONEY_OFF_MC_LIST_ERROR.getRespCode(), RespCodeEnum.GET_MONEY_OFF_MC_LIST_ERROR.getRespDesc());
        }
    }

    /**
     * @param queryMchntToClientMcStatRequest
     * @param mcCouponList
     * @return void
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/4/12
     * @Description: 查询卡券类营销活动信息
     */
    private void getMcCouponListInfo(QueryMchntToClientMcStatRequest queryMchntToClientMcStatRequest, List<StatisticsStatementQueryRespInfo> mcCouponList, String mchntArea) {

        String queryClause = queryMchntToClientMcStatRequest.getHeader().getInstId() + queryMchntToClientMcStatRequest.getMcNo()
                + queryMchntToClientMcStatRequest.getMcName() + queryMchntToClientMcStatRequest.getMcType()
                + queryMchntToClientMcStatRequest.getMcStatus() + queryMchntToClientMcStatRequest.getMcOrgId();
        try {
            StatisticsStatementInfoMapper statisticsStatementInfoMapper = new StatisticsStatementInfoMapperImpl();
            List<StatisticsStatementQueryRespInfo> objectList = statisticsStatementInfoMapper.selectStatToClientMcCouponListInfo(queryMchntToClientMcStatRequest.getHeader().getInstId(),
                    queryMchntToClientMcStatRequest.getMcNo(),
                    queryMchntToClientMcStatRequest.getMcName(),
                    queryMchntToClientMcStatRequest.getMcType(),
                    queryMchntToClientMcStatRequest.getMcStatus(),
                    queryMchntToClientMcStatRequest.getMchntNo(),
                    mchntArea);
            if (null != objectList) {
                mcCouponList.addAll(objectList);
            }
        } catch (Exception e) {
            rglog.error("根据查询条件<{}>获取卡券类营销活动列表信息失败!", queryClause);
            throw new BizException(RespCodeEnum.GET_COUPON_MC_LIST_ERROR.getRespCode(), RespCodeEnum.GET_COUPON_MC_LIST_ERROR.getRespDesc());
        }
    }

    /**
     * @param queryMchntToClientMcStatRequest
     * @param StatToClientMchntList
     * @return void
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/4/2
     * @Description: 查询对客营销活动商户统计信息
     */
    private void getAllStatToClientInfo(QueryMchntToClientMcStatRequest queryMchntToClientMcStatRequest, String mcNo, List<TMStat2CMchnt> StatToClientMchntList) {

        String queryClause = queryMchntToClientMcStatRequest.getHeader().getInstId() + mcNo;
        try {
            StatisticsStatementInfoMapper statisticsStatementInfoMapper = new StatisticsStatementInfoMapperImpl();
            List<TMStat2CMchnt> objectList = statisticsStatementInfoMapper.selectStatToClientMchntListInfo(queryMchntToClientMcStatRequest.getHeader().getInstId(),
                    mcNo, queryMchntToClientMcStatRequest.getMchntNo());
            if (null != objectList) {
                StatToClientMchntList.addAll(objectList);
            }
        } catch (Exception e) {
            rglog.error("根据查询条件<{}>获取对客营销活动商户统计信息失败!", queryClause);
            throw new BizException(RespCodeEnum.GET_MONEY_OFF_MC_LIST_ERROR.getRespCode(), RespCodeEnum.GET_MONEY_OFF_MC_LIST_ERROR.getRespDesc());
        }
    }

    /**
     * @param queryMchntToClientMcStatRequest
     * @param statToClientMchntMchntDayList
     * @return void
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/4/2
     * @Description: 查询商户对客营销活动单日统计信息
     */
    private void getAllStatToClientDayInfo(QueryMchntToClientMcStatRequest queryMchntToClientMcStatRequest, String mcNo, List<TMStat2CMchntDay> statToClientMchntMchntDayList) {
        //获取当前日期
        String nowDate = DateUtil.getCurrentDate();
        String queryClause = queryMchntToClientMcStatRequest.getHeader().getInstId() + mcNo + nowDate;
        try {
            StatisticsStatementInfoMapper statisticsStatementInfoMapper = new StatisticsStatementInfoMapperImpl();
            List<TMStat2CMchntDay> objectList = statisticsStatementInfoMapper.selectStatToClientMchntDayListInfo(queryMchntToClientMcStatRequest.getHeader().getInstId(),
                    mcNo, nowDate, queryMchntToClientMcStatRequest.getMchntNo());
            if (null != objectList) {
                statToClientMchntMchntDayList.addAll(objectList);
            }
        } catch (Exception e) {
            rglog.error("根据查询条件<{}>获取商户对客户营销活动单日统计信息失败!", queryClause);
            throw new BizException(RespCodeEnum.GET_MONEY_OFF_MC_LIST_ERROR.getRespCode(), RespCodeEnum.GET_MONEY_OFF_MC_LIST_ERROR.getRespDesc());
        }
    }

    /**
     * @param statToClientMchnt
     * @return cc.rengu.igas.momp.facade.bean.MchntToClientMcStatInfoBean
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/4/2
     * @Description: 对客营销活动统计表转换为为营销活动统计信息对象列表
     */
    private MchntToClientMcStatInfoBean convertMchntToClientMcStatInfoBean(TMStat2CMchnt statToClientMchnt) {
        MchntToClientMcStatInfoBean mchntToClientMcStatInfoBean = new MchntToClientMcStatInfoBean();
        try {
            //营销活动编号
            mchntToClientMcStatInfoBean.setMcNo(statToClientMchnt.getMcNo());
            //商户号
            mchntToClientMcStatInfoBean.setMchntNo(statToClientMchnt.getMchntNo());
            //累计消耗笔数
            mchntToClientMcStatInfoBean.setTotalQtyAcc(statToClientMchnt.getTotalQtyAcc());
            //累计消耗金额
            mchntToClientMcStatInfoBean.setTotalAmtAcc(statToClientMchnt.getTotalAmtAcc());
            //曝光次数
            mchntToClientMcStatInfoBean.setExposureQty(statToClientMchnt.getExposureQty());
            //曝光人数
            mchntToClientMcStatInfoBean.setExposurePeopleQty(statToClientMchnt.getExposurePeopleQty());
            //笔均消耗金额
            mchntToClientMcStatInfoBean.setAvgTotalAmt(statToClientMchnt.getAvgAmtAcc());

        } catch (Exception e) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
            rglog.error("转换商户对客营销活动统计信息异常,异常信息:<{}>", byteArrayOutputStream.toString());
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        return mchntToClientMcStatInfoBean;
    }

    /**
     * @param statToClientMchntDay
     * @return cc.rengu.igas.momp.facade.bean.MchntToClientMcTxnStatInfoBean
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/4/2
     * @Description: 对客营销活动单日统计表转换为为营销活动单日统计信息对象列表
     */
    private MchntToClientMcTxnStatInfoBean convertMchntToClientDayMcStatInfo(TMStat2CMchntDay statToClientMchntDay) {
        MchntToClientMcTxnStatInfoBean mchntToClientMcTxnStatInfoBean = new MchntToClientMcTxnStatInfoBean();
        try {
            //统计表中没有的字段,赋值为0
            //交易日期
            mchntToClientMcTxnStatInfoBean.setTxnDate(statToClientMchntDay.getTxnDate());
            //活动期间交易笔数
            if (!StringUtil.isNullorEmpty(statToClientMchntDay.getTotalQtyAcc())) {
                mchntToClientMcTxnStatInfoBean.setMcQty(statToClientMchntDay.getTotalQtyAcc());
            } else {
                mchntToClientMcTxnStatInfoBean.setMcQty(CommonConstant.ZERO_COMMON_CONSTANT);
            }
            //原日均交易笔数
            if (!StringUtil.isNullorEmpty(initStatData) && !CommonConstant.ZERO_COMMON_CONSTANT.equals(initStatData)) {
                mchntToClientMcTxnStatInfoBean.setOriginalQty(JSON.parseObject(initStatData).getString("dayAvgCount"));
            } else {
                mchntToClientMcTxnStatInfoBean.setOriginalQty(CommonConstant.ZERO_COMMON_CONSTANT);
            }
            //活动期间交易金额
            if (!StringUtil.isNullorEmpty(statToClientMchntDay.getTxnAmtAcc())) {
                mchntToClientMcTxnStatInfoBean.setMcAmt(statToClientMchntDay.getTxnAmtAcc());
            } else {
                mchntToClientMcTxnStatInfoBean.setMcAmt(CommonConstant.ZERO_AMOUNT);
            }
            //原日均交易金额
            if (!StringUtil.isNullorEmpty(initStatData) && !CommonConstant.ZERO_COMMON_CONSTANT.equals(initStatData)) {
                mchntToClientMcTxnStatInfoBean.setOriginalAmt(JSON.parseObject(initStatData).getString("dayAvgAmount"));
            } else {
                mchntToClientMcTxnStatInfoBean.setOriginalAmt(CommonConstant.ZERO_AMOUNT);
            }
        } catch (Exception e) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
            rglog.error("转换商户对客营销活动单日统计信息异常,异常信息:<{}>", byteArrayOutputStream.toString());
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        return mchntToClientMcTxnStatInfoBean;
    }
}
